<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .active {
            border: 1px solid red;
            width: 100px;
            height: 100px;
        }
        
        .error {
            background-color: orange;
        }
    </style>
</head>

<body>
    <div id='app'>
        <!-- class样式 -->
        <!-- 对象绑定 -->
        <div v-bind:class="{active:isActive,error:isError}">测试颜色</div>
        <button @click="handle1">样式转换</button>


        <!-- 数组绑定 -->
        <div v-bind:class="[activeClass,errorClass]">测试颜色</div>
        <button @click="handle2">样式转换</button>

        <!-- 数组和对象结合使用 -->
        <div v-bind:class="[activeClass,{error:isError}]">测试颜色</div>
        <button @click="handle2">样式转换</button>

        <!-- 简化操作 -->
        <div v-bind:class="arrClass">测试颜色</div>
        <button @click="handle2">样式转换</button>

        <!-- style样式 -->
        <!-- 对象形式 -->
        <div v-bind:style="{color:activeColor,fontSize:fontSize}"></div>
        <!-- 数组形式 -->
        <div v-bind:style="[baseStyles]"></div>
    </div>
    <script src="../js/vue.min.js"></script>
    <script>
        let vm = new Vue({
            el: '#app',
            data: {
                isActive: true,
                isError: true,
                activeClass: 'active',
                errorClass: 'error',
                arrClass: ['active', 'error'],
                activeColor: 'red',
                fontSize: '12px',
                baseStyles: {
                    border: '1px solid green',
                    height: '100px',
                    width: '100px'
                }

            },
            methods: {
                handle1: function() {
                    this.isActive = !this.isActive;
                    this.isError = !this.isError
                },
                handle2: function() {
                    this.activeClass = '';
                    this.errorClass = ''
                }
            },

        })
    </script>
</body>

</html>